package com.example.cross.controller;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.HashMap;

@RestController
@CrossOrigin(origins = "*")
public class CrossAppController {


    @RequestMapping("/api/cross")
    public HashMap<String, Object> crossTest() {
        return new HashMap<String, Object>() {{
            put("state", 200);
            put("data", "success");
        }};
    }


    public static void main(String[] args) throws ParseException {
        LocalDateTime today = LocalDateTime.now().toLocalDate().atStartOfDay();
        LocalDateTime cutOffTime = today.withHour(9).withMinute(30);
        LocalDateTime cancelDateTime = LocalDateTime.parse("2024-05-23 17:30:00", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        Date cancelDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse("2024-05-23 17:30:00");
        LocalDateTime newCancelTime = cancelDateTime.plusDays(1);
        if (cancelDateTime.isAfter(cutOffTime)) {
            cancelDate  = Date.from(newCancelTime.atZone(ZoneId.systemDefault()).toInstant());
        }

        System.out.println(cancelDate);




    }
}
